home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Freeware 2002 November
/
SGI Freeware 2002 November - Disc 1.iso
/
dist
/
fw_exmh.idb
/
usr
/
freeware
/
lib
/
exmh-2.5
/
exec.tcl.z
/
exec.tcl
Wrap
Text File
|
2002-07-08
|
1KB
|
58 lines
# exec.tcl
#
# wrapper around exec that caches location in your PATH.
# the built-in exec doesn't do this, so the directories on your
# path are constantly searched, which is silly for long lived processes.
#
if {[string length [info commands exec-orig]] == 0} {
rename exec exec-orig
trace variable env(PATH) w ExecCacheReset
}
proc Exec_Init {} {
# Just to fault in this file.
}
proc exec {args} {
global ExecCache env
# Caution: Enabling the line below will cause PGP passphrases to be logged!
# Exmh_Debug exec [join $args]
if {![regexp {^( )*([^<> ]+)(.*)$} $args all x cmd rest]} {
# auto-exec generates commands like:
# >&@stdout <@stdin /bin/ls
return [eval {exec-orig} $args]
}
if {[info exists ExecCache($cmd)]} {
if [catch {eval {exec-orig $ExecCache($cmd)} $rest} x] {
if {[info exist ExecCache($cmd)]} {
unset ExecCache($cmd)
}
return -code error $x
}
return $x
} else {
foreach dir [split $env(PATH) :] {
set path [file join $dir $cmd]
if {[file executable $path] && ![file isdirectory $path]} {
if [catch {eval {exec-orig $path} $rest} x] {
return -code error $x
}
set ExecCache($cmd) $path
return $x
}
}
}
eval {exec-orig $cmd} $rest
}
proc ExecCacheReset {args} {
global ExecCache env
if {[info exist ExecCache]} {
unset ExecCache
}
}